package com.holyland.util;

import static com.holyland.util.IHolylandConstants.SESSION_USER;

import java.util.Map;

import com.holyland.model.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class SessionCheck implements Interceptor {
	
	private static final long serialVersionUID = -7484133202627245969L;		
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {				
		Map<String, Object> session = ActionContext.getContext().getSession();
		
		User user = (User) session.get(SESSION_USER);
		
		if(user == null) {
			return "sessionError";
		} 
		
		return invocation.invoke();
	}	
}
